<extend name="../application/admin/view/common/base.html" />
<block name="x-nav"><a><cite>修改密码</cite></a></block>
<block name="body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="L_pass" class="layui-form-label">
                <span class="x-red">*</span>产品名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_pass" name="name" required=""
                       autocomplete="off" class="layui-input" value="{$info.name}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>icon
            </label>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" id="upload-file">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
                <input type="hidden" class="product-icon" value="{$info.icon}" name="icon">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>可贷金额
            </label>
            <div class="layui-input-inline">
                <input type="text"  name="quota" required=""
                       autocomplete="off" class="layui-input" value="{$info.quota}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>跳转地址
            </label>
            <div class="layui-input-inline">
                <input type="text"  name="link" required=""
                       autocomplete="off" class="layui-input" value="{$info.link}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>贷款期限(天)
            </label>
            <div class="layui-input-inline">
                <input type="text"  name="term" required=""
                       autocomplete="off" class="layui-input" value="{$info.term}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>放款时间(分钟)
            </label>
            <div class="layui-input-inline">
                <input type="text"  name="loanTime" required=""
                       autocomplete="off" class="layui-input" value="{$info.loanTime}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>日利率(%)
            </label>
            <div class="layui-input-inline">
                <input type="text"  name="interestRate" required=""
                       autocomplete="off" class="layui-input" value="{$info.interestRate}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>排序
            </label>
            <div class="layui-input-inline">
                <input type="text"  name="sort" required=""
                       autocomplete="off" class="layui-input" value="{$info.sort}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>标签
            </label>
            <div class="layui-input-block">
                <input type="checkbox" name="tags[isNew]" value="1" title="最新" <if condition="$info.isNew eq 1">checked</if>>
                <input type="checkbox" name="tags[isHot]" value="1" title="最热"  <if condition="$info.isHot eq 1">checked</if>>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                保存
            </button>
        </div>
    </form>
</block>
<block name="bottom">
    <script>
        layui.use(['form','layer','upload'], function(){
            $ = layui.jquery;
            var form = layui.form
                ,layer = layui.layer
                ,upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#upload-file' //绑定元素
                ,url: '/admin/upload' //上传接口
                ,done: function(res){
                    $('.product-icon').val(res.info.file);
                }
                ,error: function(){
                    _alert('上传失败');
                }
            });

            //监听提交
            form.on('submit(add)', function(data){
                var params = new URLSearchParams();
                $.each(data.field,function (k,v) {
                    params.append(k,v);
                })
                instance.post('/admin/product.edit.do?id={$info.id}',params)
                    .then(function (response) {
                        var data = response.data;
                        if(data.status == 1){
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            parent.location.reload();
                        }else{
                            _alert(data.msg);
                        }
                    })
                    .catch(function (error) {
                        console.log(error)
                    });
                return false;
            });


        });
    </script>
</block>